import { OptionsType } from '@micro-app/types';
import microApp from '@micro-zoe/micro-app';
import { useEffect } from 'react';

type MicroAppProps = null | OptionsType;

const useMicroApp = () => {
    // 监听子应用的生命周期事件
    microApp.addGlobalDataListener((data: any) => {
        console.log('Global data changed:', data);
    });

    microApp.start({
        'router-mode': 'state',
        lifeCycles: {
            created(e, appName) {
                console.log('子应用创建', appName);
            },
            beforemount(e, appName) {
                console.log('子应用即将挂载', appName);
            },
            mounted(e, appName) {
                console.log('子应用挂载完成', appName);
            },
            unmount(e, appName) {
                console.log('子应用已经卸载', appName);
            },
            error(e, appName) {
                console.log('子应用报错', appName);
            },
            afterhidden(e, appName) {
                console.log('子应用隐藏', appName);
                microApp.unmountApp(appName);
            },
            beforeshow(e, appName) {
                console.log('子应用即将显示', appName);
            },
            aftershow(e, appName) {
                console.log('子应用显示完成', appName);
            },
        },
        // 控制基座应用是否可以设置document的属性
        customProxyDocumentProps: new Map([['title', (value: any) => {}]]),
    });
}

export default useMicroApp;